local tonumber = GLOBAL.tonumber

function GLOBAL.musha_print(...)
	print("MUSHA_DEBUGGER:", ...)
end

function GLOBAL.RandomChoice(table)
	return table[math.random(#table)]
end

function GLOBAL.IsNearDanger(inst)
	local hounded = GLOBAL.TheWorld.components.hounded
	if hounded ~= nil and (hounded:GetWarning() or hounded:GetAttacking()) then
		return true
	end
	local burnable = inst.components.burnable
	if burnable ~= nil and (burnable:IsBurning() or burnable:IsSmoldering()) then
		return true
	end
	-- See entityreplica.lua (for _combat tag usage)
	local nospiderdanger = inst:HasTag("spiderwhisperer") or inst:HasTag("spiderdisguise")
	local nopigdanger = not inst:HasTag("monster")
	--Danger if:
	-- being targetted
	-- OR near monster that is not player
	-- ignore shadow monsters when not insane
	return GLOBAL.FindEntity(
		inst,
		10,
		function(target)
			return (target.components.combat ~= nil and target.components.combat.target == inst) or
				((target:HasTag("monster") or (not nopigdanger and target:HasTag("pig"))) and not target:HasTag("player") and
					not (nospiderdanger and target:HasTag("spider")) and
					not (inst.components.sanity:IsSane() and target:HasTag("shadowcreature")))
		end,
		nil,
		nil,
		nopigdanger and {"monster", "_combat"} or {"monster", "pig", "_combat"}
	) ~= nil
end
